package org.example.demoarticle.Controller;

import io.jsonwebtoken.Claims;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.ibatis.annotations.Delete;
import org.example.demoarticle.Service.ArticleService;
import org.example.demoarticle.Service.UserService;
import org.example.demoarticle.pojo.*;
import org.example.demoarticle.util.jwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RequestMapping("/zut")
@RestController
public class ArticleController {
    @Autowired
    UserService userService;
    @Autowired
    ArticleService articleService;
    @RequestMapping("/article")
    public ResultByArticle list(String username, String usertype, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer pageSize, String className, String creator, String category, String stem, @DateTimeFormat(pattern = "yyyy-mm-dd-hh-mm-ss") LocalDate fromDate, @DateTimeFormat(pattern = "yyyy-mm-dd-hh-mm-ss") LocalDate toDate) {
        PageBean pageBean = articleService.pageList(username,usertype,current,pageSize,className,creator,category,stem,fromDate,toDate);
        return ResultByArticle.succeed(pageBean);
    }
    @DeleteMapping("/article/{id}")
    public ResultByLogin delete(@PathVariable("id") Integer id) {
        articleService.delete(id);
        return ResultByLogin.success();
    }
    @PostMapping("/article")
    public ResultByArticle insertArticle(@RequestBody ArticleInsert article) {
        articleService.Insert(article);
        return ResultByArticle.succeed(article);
    }
    @PutMapping("/article/{id}")
    public ResultByArticle updateArticle(@PathVariable("id") Integer id,@RequestBody ArticleInsert article) {
         articleService.Update(id,article);
         return ResultByArticle.succeed(article);
    }
    @GetMapping("/article/{id}")
    public ResultByArticle Select(@PathVariable("id") Integer id) {
        Article article=articleService.Select(id);
        return ResultByArticle.succeed(article);
    }
}
